import { GetAllOrgTreeData } from '/@/api/demo/system';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();

export const columns: BasicColumn[] = [
  {
    title: t('routes.table.accountManagement.id'),
    dataIndex: 'id',
    fixed: 'left',
    width: 120,
  },
  {
    title: t('routes.table.accountManagement.name'),
    dataIndex: 'name',
    width: 120,
  },
  {
    title: t('routes.table.accountManagement.usedHost'),
    dataIndex: 'usedHost',
    width: 120,
  },
  {
    title: t('routes.table.accountManagement.sex'),
    dataIndex: 'sex',
    width: 80,
  },
  {
    title: t('routes.table.accountManagement.sign'),
    dataIndex: 'sign',
    width: 80,
    slots: { customRender: 'sign' },
  },
  {
    title: t('routes.table.accountManagement.ipAddress'),
    dataIndex: 'ipAddress',
    width: 100,
  },
  {
    title: t('routes.table.accountManagement.email'),
    dataIndex: 'email',
    width: 180,
  },
  {
    title: t('routes.table.accountManagement.tel'),
    dataIndex: 'tel',
    width: 150,
  },
  {
    title: t('routes.table.accountManagement.address'),
    dataIndex: 'address',
    width: 150,
  },
  {
    title: t('routes.table.accountManagement.createTime'),
    dataIndex: 'createTime',
    width: 150,
    slots: { customRender: 'createTime' },
  },
  {
    title: t('routes.table.accountManagement.creator'),
    dataIndex: 'creator',
    width: 150,
  },
  {
    title: t('routes.table.accountManagement.remark'),
    dataIndex: 'remark',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: t('routes.table.accountManagement.id'),
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'name',
    label: t('routes.table.accountManagement.name'),
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: t('routes.table.accountManagement.id'),
    component: 'Input',
    required: true,
    defaultValue: '',
  },
  {
    field: 'name',
    label: t('routes.table.accountManagement.name'),
    component: 'Input',
    required: true,
    defaultValue: '',
  },
  {
    field: 'password',
    label: t('routes.table.accountManagement.password'),
    component: 'InputPassword',
    required: true,
    defaultValue: '',
  },
  {
    field: 'sex',
    label: t('routes.table.accountManagement.sex'),
    component: 'RadioGroup',
    defaultValue: '男',
    componentProps: {
      options: [
        { label: t('routes.table.accountManagement.man'), value: '男' },
        { label: t('routes.table.accountManagement.woman'), value: '女' },
      ],
    },
  },
  // {
  //   field: 'signFile',
  //   label: t('routes.table.accountManagement.sign'),
  //   component: 'Upload',
  //   defaultValue: {},
  //   componentProps: {
  //     api: UpLoadPersonBMP,
  //   },
  // },
  {
    field: 'ipAddress',
    label: t('routes.table.accountManagement.ipAddress'),
    component: 'Input',
    defaultValue: '',
  },
  {
    field: 'email',
    label: t('routes.table.accountManagement.email'),
    component: 'Input',
    defaultValue: '',
    rules: [
      {
        type: 'email',
        message: t('routes.table.accountManagement.emailPlaceholder'),
      },
    ],
  },
  {
    field: 'tel',
    label: t('routes.table.accountManagement.tel'),
    component: 'Input',
    defaultValue: '',
    rules: [
      {
        pattern: /^1[3-9]\d{9}$/,
        message: t('routes.table.accountManagement.telPlaceholder'),
      },
    ],
  },
  {
    field: 'address',
    label: t('routes.table.accountManagement.address'),
    component: 'InputTextArea',
    defaultValue: '',
  },
  {
    field: 'orgMembers',
    label: t('routes.table.accountManagement.department'),
    component: 'ApiTreeSelect',
    defaultValue: [],
    componentProps: {
      api: GetAllOrgTreeData,
      replaceFields: {
        title: 'title',
        key: 'orgId',
        value: 'orgId',
        children: 'childrenOrg',
      },
      multiple: true,
      getPopupContainer: () => document.body,
    },
  },
  {
    label: t('routes.table.accountManagement.remark'),
    field: 'remark',
    component: 'InputTextArea',
    defaultValue: '',
  },
];

export const GetRoleColumns: BasicColumn[] = [
  {
    title: t('routes.table.accountManagement.role'),
    dataIndex: 'name',
  },
];

export const GetDepColumns: BasicColumn[] = [
  {
    title: t('routes.table.accountManagement.department'),
    dataIndex: 'name',
  },
];
